package com.programming.movie.manager.impl;

import java.util.List;

import com.programming.common.exception.DAOException;
import com.programming.common.exception.ManagerException;
import com.programming.common.page.Page;
import com.programming.movie.dao.CommentDAO;
import com.programming.movie.dataobject.Comment;
import com.programming.movie.manager.CommentManager;

public class CommentManagerImpl implements CommentManager {
	private CommentDAO commentDAO;

	public void setCommentDAO(CommentDAO commentDAO) {
		this.commentDAO = commentDAO;
	}

	@Override
	public boolean delete(Long id) throws ManagerException {
		try {
			this.commentDAO.delete(id);
		} catch (DAOException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public Comment getById(Long id) throws ManagerException {
		// TODO Auto-generated method stub
		try {
			return this.commentDAO.getById(id);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Page query(Comment comment, int start, int limit) throws ManagerException {
		try {
			return this.commentDAO.query(comment, start, limit);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<Comment> queryList(Comment comment) throws ManagerException {
		try {
			return this.commentDAO.queryList(comment);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return null;

	}

	@Override
	public boolean save(Comment comment) throws ManagerException {
		if (comment.getId() != null) {
			try {
				this.commentDAO.update(comment);
			} catch (DAOException e) {
				e.printStackTrace();
			}
		} else {
			try {
				this.commentDAO.insert(comment);
			} catch (DAOException e) {
				e.printStackTrace();
			}
		}
		return true;
	}

}
